﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Web.UI.Controls;
using DP.Common;


namespace CRM.Web.FaqManage
{
    public partial class FaqRightListPop : Common.PageBase
    {
        public string ModifyUrl = "FaqDetialView.aspx?SRCID={0}&CATNAME={1}";
        T_FAQ_SRC_BLL sBll = new T_FAQ_SRC_BLL();

        private UserLoginInfo _loginInfo;
        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            UserLoginInfo.CheckLoginInfo();
            _loginInfo = UserLoginInfo.GetLoginInfo();
            PageHelper.SetPrePageUrl(this.Page);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                gvDataBinding();
            }
        }

        /// <summary>
        /// 页面数据绑定
        /// </summary>
        private void gvDataBinding()
        {
            ModifyUrl = "FaqDetialView.aspx?SRCID={0}&CATNAME=" + PageHelper.GetQueryString(this.Page, "CATNAME");
            string sql = String.Format(" AND CATID LIKE '{0}%' and BUSINESSDIVISIONCODE = '{1}' ORDER BY CREATEDATE DESC", PageHelper.GetQueryString(this.Page, "CATID"), _loginInfo.UserEntity.BUSINESSDIVISIONCODE);
            if (PageHelper.GetQueryString(this.Page, "CATID") == "-9")
            {
                sql = String.Format(" AND BUSINESSDIVISIONCODE = '{0}' and SRCTITLE LIKE '%{1}%' ORDER BY CREATEDATE DESC", _loginInfo.UserEntity.BUSINESSDIVISIONCODE, PageHelper.GetQueryString(this.Page, "SRCTITLE"));
            }
            else if (PageHelper.GetQueryString(this.Page, "CATID") == "-8")
            {
                sql = String.Format(" AND BUSINESSDIVISIONCODE = '{0}' ORDER BY CREATEDATE DESC", _loginInfo.UserEntity.BUSINESSDIVISIONCODE);
            }

            this.divSEARCH.Visible = true;
            List<T_FAQ_SRC_Entity> list = new List<T_FAQ_SRC_Entity>();
            list = sBll.GetList(sql);

            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = list;
            pds.AllowPaging = true;
            pds.PageSize = 20;
            int currentPage = Convert.ToInt32(Request["page"]);
            //设当前页
            pds.CurrentPageIndex = currentPage;
            //设几个超链接
            if (!pds.IsFirstPage)
            {
                lnkUp.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);
            }

            if (!pds.IsLastPage)
            {
                lnkDown.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1);
            }
            lbl_info.Text = "第" + (currentPage + 1) + "页/共" + pds.PageCount + "页";
            Repeater1.DataSource = pds;
            Repeater1.DataBind();

            this.lblTitle.Text = "FAQ >> " + PageHelper.GetQueryString(this.Page, "CATNAME");

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string url = "FaqRightListPop.aspx?CATID=-9&CATNAME=全文检索&SRCTITLE=" + txtSRCKEY.Text;
            Response.Redirect(url);
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

        }
    }
}
